package grad.nxu.recruitsystem.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import grad.nxu.recruitsystem.domain.Role;
import grad.nxu.recruitsystem.service.RoleService;
import grad.nxu.recruitsystem.vo.ApiResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: recruitSystem
 * @Package_name: grad.nxu.recruitsystem.controller
 * @Date: 2023/3/15 8:40
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    /**
     * 获取所有角色接口
     *
     * @param pageSize   每页大小
     * @param pageNumber 当前页
     * @return 返回结果
     */
    @ApiOperation("获取所有角色接口")
    @GetMapping("/admin/all")
    public ApiResponse<List<Role>> getAll(boolean isReplied, Integer pageSize, Integer pageNumber) {
        ApiResponse<List<Role>> apiResponse = new ApiResponse<>();
        Page<Role> page = new Page<>(pageNumber, pageSize);
        Page<Role> rolePage;
        try {
            rolePage = roleService.page(page);
            apiResponse.setCode(200).setSuccess(true).setData(rolePage.getRecords());
        } catch (Exception e) {
            apiResponse.setCode(500).setSuccess(false).setMessage("服务器错误");
        }
        return apiResponse;
    }
}
